import { h } from 'vue';
import { BasicColumn } from '@/components/Table';

// 类型映射
const typeMap = {
  recharge: '充值',
  withdraw: '提现',
  transfer: '转账',
  refund: '退款',
  bank_in: '回款',
};

export const columns: BasicColumn[] = [
  {
    title: '账户ID',
    key: 'account_id',
    width: 140,
    ellipsis: {
      tooltip: true,
    },
  },
  {
    title: '类型',
    key: 'type',
    width: 80,
    render(record) {
      const typeText = typeMap[record.type] || record.type;
      const isRefund = record.type === 'refund';
      
      return h(
        'span',
        {
          style: {
            color: isRefund ? '#d03050' : undefined,
          },
        },
        typeText
      );
    },
  },
  {
    title: '变动金额',
    key: 'amount',
    width: 100,
    render(record) {
      const amount = parseFloat(record.amount);
      return h(
        'span',
        {
          style: {
            color: amount >= 0 ? '#18a058' : '#d03050',
          },
        },
        `¥${amount.toFixed(2)}`
      );
    },
  },
  {
    title: '变动后余额',
    key: 'after_balance',
    width: 100,
    render(record) {
      const balance = parseFloat(record.after_balance);
      return `¥${balance.toFixed(2)}`;
    },
  },
  // {
  //   title: '上游来源',
  //   key: 'upstream',
  //   width: 120,
  //   render(record) {
  //     return record.upstream || '-';
  //   },
  // },
  // {
  //   title: '备注',
  //   key: 'remark',
  //   width: 120,
  //   ellipsis: {
  //     tooltip: true,
  //   },
  //   render(record) {
  //     return record.remark || '-';
  //   },
  // },
  {
    title: '创建时间',
    key: 'created_at',
    width: 140,
  },
  {
    title: '更新时间',
    key: 'updated_at',
    width: 140,
  },
];